<?php
if(isset($_POST['ok'])){
	$typename=$_POST['txttype_name_name'];
	$err="";	
	$sql="select * from type where type_name='$typename'";
	$query=mysql_query($sql);
	if(mysql_num_rows($query)>0){
		$err="Đã tồn tại menu này";
	}else{
		$sql="insert into type(type_name) values ('$typename')";
		mysql_query($sql);
	}
}
global $err;
if($err){
	echo "<p align='center'><font color='red' align>",$err,"</font></p>";
}
?>
<p align="center"><font color="red" id=err></font></p>
<table id="tablemenu">
<form method='post' onsubmit="return validatetype(this)">
	<tr>
		<th>Tên menu</th><th>Hành động</th>
	</tr>
	<?php
	$sql="select * from type";
	$query=mysql_query($sql);
	while($data=mysql_fetch_assoc($query)){
		echo "<tr>";
		echo "<td>$data[type_name]</td><td><a href='index.php?page=delete_type&id=$data[type_id]' onclick='return confirmdelete()'>Xóa</a></td>";
		echo "</tr>";
	}
	?>
	<tr>
	
		<td><input type="text" name="txttype_name" size='25' /></td><td><input type="submit" name='ok' value="Add" /></td>
	
	</tr>
</form>
</table>